<?php
if($_POST['submit']=='')
{
    $threadid = $_GET['threadid'];
    $query = "select * from ".DBPREFIX."exam_thread as a inner join ".DBPREFIX."exam as b on a.exam_id=b.exam_id where a.thread_id=".$threadid;
    $result =$db->query($query);
    $thread_info =array();
    while($row = $db->fetch_array($result))
    {
        $thread_info = $row;
    }
}
else{
    $thread_id = $_POST['thread_id'];
    $question_type = intval($_POST['question_type']);
    if($question_type ==0)
    {
        fs_showmsg('类型不能为空!');
    }
    $question_des = $_POST['question_des'];
    $sort = $_POST['sort'];
    $exam_id = $_POST['exam_id'];
    if($question_type!=''&&$question_des!=''&&$sort!=''){
        $query  = "update ".DBPREFIX."exam_thread set thread_type=".$question_type.",thread_des='".$question_des."',thread_sort=".$sort." where thread_id=".$thread_id;
        $result = $db->query($query);
        if($result){
            fs_showmsg("更新成功!","?do=addthreadquestion&examid=".$exam_id);
        }
        else{
            fs_showmsg('更新失败');
        }
    }
}
?>
<div class="main_box">
        <div class="add_question_box">
            <div class="submenu_t">
                    <ul>
                        <li><a href="?do=elist">试卷列表</a> | </li>
                        <li><a href="?do=add_e">编写试卷</a> | </li>
                    </ul>
            </div>
                 <form action="#" method="post" onsubmit="return checkbox(new Array(new Array('question_des','类型说明不能为空'),new Array('sort','排序不能为空')))">
                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
                                <tr><td colspan="2">
                                        <span style="color:red">说明:</span><br/>
                                        1:排序序号是一个数字,数字越小,题目越靠前.<br/>
                                        2:类型说明一般包括该类型下题目的数量和分值以及题目的性质.比如:(共5题,每题3分,每个题有且只有一个是正确的)<br/>
                                    </td>
                                </tr>
                                <tr>
                                        <td width="15%" align="right">试卷标题:</td><td width="75%"><input type="text" size="40" name="exam_name" id="exam_name" disabled="disabled" value="<?php echo $thread_info['exam_name'];?>" />*此处不能修改</td>
                                </tr>

                                <tr>
                                                <td align="right">试题类型:</td>
                                                <td><select name="question_type" id="question_type"><option value="0">请选择:</option><option value="1" <?php if($thread_info['thread_type']==1) echo 'selected';?>>单选题</option><option value="2" <?php if($thread_info['thread_type']==2) echo 'selected';?>>多选题</option><option value="3" <?php if($thread_info['thread_type']==3) echo 'selected';?>>判断题</option></select></td>
                                </tr>
                                <tr>
                                                <td align="right">类型说明:</td>
                                <td><textarea cols="30" row="10" name="question_des" id="question_des"><?php echo $thread_info['thread_des']?></textarea></td>
                                </tr>
                                <tr>
                                                <td align="right">排序:</td><td><input type="text" id="sort" name="sort" value="<?php echo $thread_info['thread_sort']?>"/><input type="hidden" name="thread_id" value="<?php echo $_GET['threadid']?>"/><input type="hidden" name="exam_id" value="<?php echo $thread_info['exam_id']?>"/></td>
                                </tr>

                                <tr>
                                    <td align="center" colspan="2"><input type="submit" name="submit" value="完成编辑"/></td>
                                </tr>
                         
                </table>
               </form>
        </div>
</div>